﻿using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.SystemUI;
using System.Windows.Forms;

namespace Swsk33.ArcMapDevelop
{
	/// <summary>
	/// 显示选中要素类的OID和类型
	/// </summary>
	public class GetSelectFeatureOIDAndType : ICommand
	{
		/// <summary>
		/// ArcMap钩子对象
		/// </summary>
		private IApplication arcmapObject;

		/// <summary>
		/// 按钮图标
		/// </summary>
		public int Bitmap
		{
			get;
			set;
		}

		/// <summary>
		/// 按钮名
		/// </summary>
		public string Caption
		{
			get { return "获取选中要素类OID和类型"; }
		}

		/// <summary>
		/// 工具集分类名
		/// </summary>
		public string Category
		{
			get { return "swsk33"; }
		}

		public bool Checked
		{
			get { return false; }
		}

		public bool Enabled
		{
			get
			{
				IMxDocument document = (IMxDocument)arcmapObject.Document;
				IMap map = document.FocusMap;
				if (map.LayerCount > 0)
				{
					return true;
				}
				else
				{
					return false;
				}
			}
		}

		public int HelpContextID
		{
			get;
			set;
		}

		public string HelpFile
		{
			get;
			set;
		}

		public string Message
		{
			get { return "获取选中要素类OID和类型"; }
		}

		public string Name
		{
			get { return "获取选中要素类OID和类型"; }
		}

		public void OnClick()
		{
			IMxDocument document = (IMxDocument)arcmapObject.Document;
			IMap map = document.FocusMap;
			IEnumFeature featureSelection = (IEnumFeature)map.FeatureSelection;
			IFeature feature = featureSelection.Next();
			while (feature != null)
			{
				string id = feature.OID.ToString();
				var type = feature.Shape.GeometryType;
				string typeString;
				switch (type)
				{
					case esriGeometryType.esriGeometryPoint:
						typeString = "点类型";
						break;
					case esriGeometryType.esriGeometryPolyline:
						typeString = "线类型";
						break;
					case esriGeometryType.esriGeometryPolygon:
						typeString = "面类型";
						break;
					default:
						typeString = "未知类型";
						break;
				}
				MessageBox.Show("选中图层OID：" + id + "\r\n图层类型：" + typeString);
				feature = featureSelection.Next();
			}
		}

		public void OnCreate(object Hook)
		{
			arcmapObject = (IApplication)Hook;
		}

		public string Tooltip
		{
			get { return "获取选中要素类OID和类型"; }
		}
	}
}